#pragma once

#include <memory>
#include <thread>

#include "level.hpp"
#include "util.hpp"

namespace Log
{
    struct LogFormat
    {
        LogFormat() = default;
        LogFormat(LogLevel::value level, std::string file, size_t line, std::string name, std::string payload)
            : name_(name)
            , file_name_(file)
            , payload_(payload)
            , level_(level)
            , line_(line)
            , ctime_(utils::Date::Now())
            , tid_(std::this_thread::get_id()) 
        {}

        std::string format()
        {
            struct tm t;
            localtime_r(&ctime_, &t);

            char buf[128]{};
            strftime(buf, sizeof(buf), "%H:%M:%S", &t);

            std::string tmp1 = '[' + std::string(buf) + "][";
            std::string tmp2 = '[' + std::string(LogLevel::ToString(level_)) + "][" + name_ + "][" + file_name_ + ":" + std::to_string(line_) + "]\t" + payload_ + "\n";
            
            std::stringstream ret;
            ret << tmp1 << tid_ << tmp2;

            return ret.str();
        }

        std::string name_;      // 日志器名
        std::string file_name_; // 文件名
        std::string payload_;   // 信息体
        LogLevel::value level_; // 等级
        size_t line_;           // 行号
        time_t ctime_;          // 时间
        std::thread::id tid_;   // 线程id
        
    };
}